var GameData = require('../module/GameData')();

cc.Class({
    extends: cc.Component,
    onLoad(){
        cc.director.getPhysicsManager().enabled = true;
        cc.director.getPhysicsManager().debugDrawFlags = cc.PhysicsManager.DrawBits.e_aabbBit |
            cc.PhysicsManager.DrawBits.e_pairBit |
            cc.PhysicsManager.DrawBits.e_centerOfMassBit |
            cc.PhysicsManager.DrawBits.e_jointBit |
            cc.PhysicsManager.DrawBits.e_shapeBit
        ;

        cc.director.getPhysicsManager().debugDrawFlags = 0;
    },
    // 只在两个碰撞体开始接触时被调用一次
    onBeginContact: function (contact, selfCollider, otherCollider) {

        // GameData.game_play.bullet_pool.put(selfCollider.node);
        if (otherCollider.node.name == "bullet" && selfCollider.node.name == "bullet") {

        }else {
            if (otherCollider.node.ischeck) {
                GameData.game_play.changeBullet_state(otherCollider.node, 3)
                otherCollider.node.ischeck = false;
                otherCollider.node.removeComponent(cc.PhysicsBoxCollider);
                otherCollider.node.removeComponent(cc.RigidBody);
                // otherCollider.getComponent(cc.PhysicsBoxCollider).active=false;
                // otherCollider.getComponent(cc.RigidBody).active=false;
                // otherCollider.getComponent(cc.RigidBody).linearVelocity = cc.v2(0, 0);
                // otherCollider.getComponent(cc.RigidBody).gravityScale = 0;
                // otherCollider.getComponent(cc.RigidBody).linearDamping =  0;
                for (var a = 0; a < GameData.game_play.bulletArr.length; a++) {
                    if (GameData.game_play.bulletArr[a].launch_state == "destorying") {
                        GameData.game_play.bulletArr.splice(a, 1);
                        a--;
                    }
                }
                GameData.game_play.createBullet();
            }
        }
        // console.log("onBeginContact")
    },

    // 只在两个碰撞体结束接触时被调用一次
    onEndContact: function (contact, selfCollider, otherCollider) {
        // console.log("onEndContact")
    },

    // 每次将要处理碰撞体接触逻辑时被调用
    onPreSolve: function (contact, selfCollider, otherCollider) {
        // console.log("onPreSolve")
    },

    // 每次处理完碰撞体接触逻辑时被调用
    onPostSolve: function (contact, selfCollider, otherCollider) {
        // console.log("onPostSolve")
    }
});